﻿using myAutoExcuteJobService.Tools;
using mybolg.DAL;
using mybolg.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mybolg.Controllers
{
    public class JsonDateController : Controller
    {
        Models.BlogEntities11 DBblog = new BlogEntities11();

        /// <summary>
        /// 得到说说数据通过页码和个数
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="Number"></param>
        /// <returns></returns>
       public JsonResult getSSDataByPageAndNumber(int Page,int Number)
       {
           var blogMainPage = new Blog_MainPage();

           try
           {
               Dictionary<string, object> dic = blogMainPage.getShuoShuoByPageAndNumber(Page, Number);
           }catch(Exception e){
               return Json(e.ToString(),JsonRequestBehavior.AllowGet);
           }
           return Json(blogMainPage.getShuoShuoByPageAndNumber(Page, Number), JsonRequestBehavior.AllowGet);
       }

        public JsonResult getmyTableByTableInfo(string Tinfo_json)
        {
            TableInfo tinfo = new TableInfo();
            tinfo=JsonHelper.DeserializeJsonToObject<TableInfo>(Tinfo_json);
            myTable mt = new myTable(tinfo);
            TableResult tr = mt.getTableResult<DMP_Bolg_Shuoshuo>();
            TableInfo ti = mt.getTableInfo();
            



            Dictionary<string, object> Table = new Dictionary<string, object>();
            Table.Add("TableInfo",ti);
            Table.Add("TableResult_Count",tr.Count);
            Table.Add("TableResult_DbList", tr.Dblist<DMP_Bolg_Shuoshuo>());
            return Json(Table,JsonRequestBehavior.AllowGet);

        }

        //说说点赞 分享 浏览数据的处理
        public JsonResult updateSSPSV(string Type,string ssid)
        {
            string sqlstr = "UPDATE dbo.DMP_Bolg_Shuoshuo SET "; 
            switch (Type)
            {
              case  "PageViewNumber":
                    sqlstr += "PageViewNumber =(select top 1 PageViewNumber from dbo.DMP_Bolg_Shuoshuo where id='" + ssid + "')+1 WHERE id='" + ssid + "' ";
                    break;
               case "PointNumber":
                    sqlstr += "PointNumber =(select top 1 PointNumber from dbo.DMP_Bolg_Shuoshuo where id='" + ssid + "')+1 WHERE id='" + ssid + "' ";
                    break;
               case "shareNumber":
                    sqlstr += "shareNumber =(select top 1 shareNumber from dbo.DMP_Bolg_Shuoshuo where id='" + ssid + "')+1 WHERE id='" + ssid + "' ";
                    break;
                default:break;
            }
            DBblog.Database.ExecuteSqlCommand(sqlstr);
            return Json(true);


        }

    }
}
